<!--售票员层级差异待协查-->
<template>
  <div class="sw-st-stock addEdit el-card is-always-shadow el-card__body">
    <el-dialog
      title="操作"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      @close="closed"
      width="950px">
      <avue-form v-if="isReload" ref="form" class="addEdit" :option="option" v-model="formData">
        <template slot="scrapSubtotal" slot-scope="{row, size}">
          <el-input
            v-model="formData.scrapSubtotal"
            placeholder="废票小计"></el-input>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button  type="primary"  @click="handleSubmit" >保存</el-button>
          <el-button  @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>

<script>

  import { addObj, putObj } from '@/api/subwaystm/swststock'
  export default {
    components:{
    },
    data() {
      return {
        showType:1,
        isReload:true,
        dialogVisible:true,
        option:{},
        formData:{
          scrapSubtotal:0,
          balanceToday:0
        }
    }
    },
    created() {
      this.showType = this.$parent.showType;
      this.getOption();
    },
    methods: {
      handleSubmit(){
        this.$refs.form.validate(vaild=>{
        if(vaild){
          if(this.showType == 0){
            addObj(this.formData).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.closed();
                this.$parent.getList(this.$parent.page);
              }else{
                this.$message.error(res.data.msg);
              }
            })
          }else{
            putObj(this.formData).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.closed();
                this.$parent.getList(this.$parent.page);
              }else{
                this.$message.error(res.data.msg);
              }
            })
          }
          }
        })
      },
      recallShow(row){
        if(null != row){
          Object.assign(this.formData,row);
        }else{
          this.formData.scrapSubtotal = 0;
          this.formData.balanceToday = 0;
          this.formData.balanceLastday = 0;
          this.formData.transferStation = 0;
          this.formData.leaveStation = 0;
          this.formData.distributionStation = 0;
          this.formData.agmRecovery = 0;
          this.formData.boxOfficeSale = 0;
	  this.formData.ticketReplace = 0;
          this.formData.tvmSellOut = 0;
          this.formData.internetSales = 0;
          this.formData.bomScrapTicket = 0;
          this.formData.tvmScrapTicket = 0;
          this.formData.agmScrapTicket = 0;
          this.formData.networkScrapTicket = 0;
          this.formData.handTicket = 0;
          this.formData.artificialRecovery = 0;
          this.formData.statisticsDate = new Date();
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.addVisableDialog=false;
      },
      getOption(){
        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
            icon:'',
            label: '',
            prop: 'group',
            column: [{
              "type": "input",
              "label": "唯一标识",
              "prop": "id",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "线路编码不能重复",
              "prop": "lineCode",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "车站编码不能重复",
              "prop": "stationCode",
              hide: true,
              display: false
            },	  {
              "type": "date",
              "label": "日期",
              "prop": "statisticsDate",
              format: 'yyyy-MM-dd',
              valueFormat: 'yyyy-MM-dd',
              search: false,
              disabled: this.showType == 1
            }, {
              label: '票种',
              prop: 'ticketTypeEn',
              search: true,
              type: 'select',
              cascaderItem: ["ticketTypeParamEn"],
              dicUrl: "/support/swpmticketcardtype/dict",
              props: {
                label: 'mainName',
                value: 'mainEnName'
              },
              rules: [{
                required: true,
                message: '请选择票种',
                trigger: 'blur'
              }],
              display: true,
              disabled: this.showType == 1
            },{
              label: '车票名称',
              prop: 'ticketTypeParamEn',
              type: 'select',
              search: true,
              dicFlag: false,
              props: {
                label: 'subName',
                value: 'subEnName'
              },
              dicUrl: "/support/swpmticketcardtypeparam/dictAll/{{key}}",
              display: true ,
              rules: [{
                required: true,
                message: '请选择车票名称',
                trigger: 'blur'
              }],
              disabled: this.showType == 1
            }, {
              "type": "number",
              "label": "上日结存",
              "prop": "balanceLastday",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = data.value + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "调入本站",
              "prop": "transferStation",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + data.value + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "调出本站",
              "prop": "leaveStation",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - data.value - this.formData.handTicket 
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "配入本站",
              "prop": "distributionStation",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + data.value + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "AGM回收",
              "prop": "agmRecovery",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + data.value  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "票房售出",
              "prop": "boxOfficeSale",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - data.value - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            }, {
              "type": "number",
              "label": "车票替换",
              "prop": "ticketReplace",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                   - this.formData.boxOfficeSale - data.value - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "TVM售出",
              "prop": "tvmSellOut",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - data.value - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "STM售出",
              "prop": "internetSales",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - data.value - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "BOM废票",
              "prop": "bomScrapTicket",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.scrapSubtotal = data.value + this.formData.tvmScrapTicket +this.formData.agmScrapTicket +this.formData.networkScrapTicket;
                else
                  this.$message.warning("数值过大");
              },
              //editDisabled: true
            },	  {
              "type": "number",
              "label": "TVM废票",
              "prop": "tvmScrapTicket",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.scrapSubtotal = this.formData.bomScrapTicket +data.value +this.formData.agmScrapTicket +this.formData.networkScrapTicket;
                else
                  this.$message.warning("数值过大");
              },
              //editDisabled: true
            },	  {
              "type": "number",
              "label": "AGM废票",
              "prop": "agmScrapTicket",
              change:(data) => {
                if(data.value <= 999999999)
		 {
                  this.formData.scrapSubtotal = this.formData.bomScrapTicket + this.formData.tvmScrapTicket + data.value +this.formData.networkScrapTicket;
		  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + data.value + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                }else{
                  this.$message.warning("数值过大");
		  }
              },
              //editDisabled: true
            },	  {
              "type": "number",
              "label": "STM废票",
              "prop": "networkScrapTicket",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.scrapSubtotal = this.formData.bomScrapTicket + this.formData.tvmScrapTicket + this.formData.agmScrapTicket + data.value;
                else
                  this.$message.warning("数值过大");
              },
              //editDisabled: true
            },	  {
              "type": "number",
              "label": "废票小计",
              "prop": "scrapSubtotal",
              slot:true,
              disabled: true,
            },	  {
              "type": "number",
              "label": "上交车票",
              "prop": "handTicket",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + this.formData.artificialRecovery
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - data.value;
                else
                  this.$message.warning("数值过大");
              },
              //disabled: this.showType == 1
            },	  {
              "type": "number",
              "label": "人工回收",
              "prop": "artificialRecovery",
              change:(data) => {
                if(data.value <= 999999999)
                  this.formData.balanceToday = this.formData.balanceLastday + this.formData.transferStation + this.formData.distributionStation + this.formData.agmRecovery  + this.formData.agmScrapTicket + data.value
                  - this.formData.boxOfficeSale - this.formData.ticketReplace - this.formData.tvmSellOut - this.formData.internetSales - this.formData.leaveStation - this.formData.handTicket;
                else
                  this.$message.warning("数值过大");
              },
              //editDisabled: true
            },	  {
              "type": "number",
              "label": "本日结存",
              "prop": "balanceToday",
              disabled: true
            },	  {
              "type": "textarea",
              "label": "备注",
              "prop": "remark",
              span: 24
            },	  {
              "type": "input",
              "label": "部门ID",
              "prop": "deptId",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "创建人ID",
              "prop": "creatorId",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "创建人名称",
              "prop": "creatorName",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "创建时间",
              "prop": "createTime",
              hide: true,
              display: false
            },	  {
              "type": "input",
              "label": "数据更新时间",
              "prop": "updateTime",
              hide: true,
              display: false
            }]
          }]
        }
        this.isReload=false;
        this.$nextTick(()=>{
          this.isReload=true;
        })
      }
    },
    mounted() {

    }
  }
</script>
<style lang="scss">
  .shouPiaoYuanPKCYDXC{
    .shouPiaoYuanPKCYDXCForm{
      .avue-group[index='1']{
        .el-form-item{
          min-width: 450px;
        }
        .avue-form__row{
          width: 100%;
        }
      }

    }
  }

</style>
